package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.hjq.widget.layout.SettingBar;
import com.qiantu.api.entity.DeviceTriggerType;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/09/22
 *    desc   : 状态数据列表
 */
public final class DeviceStatusAdapter extends AppAdapter<DeviceTriggerType> {

    public DeviceStatusAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private ViewHolder() {
            super(R.layout.item_device_status);
        }

        @Override
        public void onBindView(int position) {
            DeviceTriggerType deviceTriggerType = getItem(position);
            SettingBar settingBar = (SettingBar) itemView;
            int res = getResources().getIdentifier(deviceTriggerType.getName(), "string", getContext().getPackageName());
            settingBar.setLeftText(res);
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}